﻿using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyLib.Web.UI {
	/// <summary>
	/// 自定义签条
	/// </summary>
	[DefaultProperty("Text")]
	[ToolboxData("<{0}:MyLabel runat=server></{0}:MyLabel>")]
	public class MyLabel : Label {
		/// <summary>
		/// 
		/// </summary>
		private const string REQUIRED_CLASS = "required";

		/// <summary>
		/// 
		/// </summary>
		private const string REQUIRED_MARK = "(*)";

		/// <summary>
		/// 是否是必填项
		/// </summary>
		[Category("Action")]
		[Description("表示该项是否是必填项")]
		[DefaultValue(false)]
		public bool Required { get; set; }

		/// <summary>
		/// 
		/// </summary>
		/// <param name="writer"></param>
		protected override void Render(HtmlTextWriter writer) {
			base.Render(writer);

			// 对于必填项, 输出一个必须填写的标志
			if (Required) {
				writer.AddAttribute(HtmlTextWriterAttribute.Class, REQUIRED_CLASS);
				writer.AddAttribute(HtmlTextWriterAttribute.Title, MyLib.Web.Properties.Main.field_is_required);
				writer.RenderBeginTag(HtmlTextWriterTag.Span);
				writer.WriteEncodedText(REQUIRED_MARK);
				writer.RenderEndTag();
			}

			writer.WriteEncodedText(":");
		}
	} // end of MyLabel.
}
